import request from '@/utils/request'

// 用户认证相关API
export const authApi = {
  // 用户登录
  login(data) {
    return request({
      url: '/api/auth/login',
      method: 'post',
      data
    })
  },
  
  // 用户注册
  register(data) {
    return request({
      url: '/api/auth/register',
      method: 'post',
      data
    })
  },
  
  // 获取用户信息
  getUserInfo() {
    return request({
      url: '/api/auth/userinfo',
      method: 'get'
    })
  },
  
  // 更新用户信息
  updateUserInfo(data) {
    return request({
      url: '/api/auth/userinfo',
      method: 'put',
      data
    })
  },
  
  // 修改密码
  changePassword(data) {
    return request({
      url: '/api/auth/change-password',
      method: 'post',
      data
    })
  }
}

// 每日健康记录相关API
export const dailyRecordApi = {
  // 保存每日记录
  saveRecord(data) {
    return request({
      url: '/api/daily/record',
      method: 'post',
      data
    })
  },
  
  // 获取某日期的每日记录
  getRecord(date) {
    return request({
      url: '/api/daily/record',
      method: 'get',
      params: { date }
    })
  },
  
  // 获取日期范围内的每日记录
  getRecords(startDate, endDate) {
    return request({
      url: '/api/daily/records',
      method: 'get',
      params: { startDate, endDate }
    })
  },
  
  // 获取最近的每日记录
  getRecentRecords(limit = 7) {
    return request({
      url: '/api/daily/records/recent',
      method: 'get',
      params: { limit }
    })
  },
  
  // 删除每日记录
  deleteRecord(recordId) {
    return request({
      url: `/api/daily/record/${recordId}`,
      method: 'delete'
    })
  }
}

// 运动记录相关API
export const exerciseApi = {
  // 创建运动记录
  createRecord(data) {
    return request({
      url: '/api/exercise/record',
      method: 'post',
      data
    })
  },
  
  // 更新运动记录
  updateRecord(recordId, data) {
    return request({
      url: `/api/exercise/record/${recordId}`,
      method: 'put',
      data
    })
  },
  
  // 获取某日期的运动记录
  getRecords(date) {
    return request({
      url: '/api/exercise/records',
      method: 'get',
      params: { date }
    })
  },
  
  // 获取日期范围内的运动记录
  getRecordsByDateRange(startDate, endDate) {
    return request({
      url: '/api/exercise/records/range',
      method: 'get',
      params: { startDate, endDate }
    })
  },
  
  // 获取最近的运动记录
  getRecentRecords(limit = 10) {
    return request({
      url: '/api/exercise/records/recent',
      method: 'get',
      params: { limit }
    })
  },
  
  // 删除运动记录
  deleteRecord(recordId) {
    return request({
      url: `/api/exercise/record/${recordId}`,
      method: 'delete'
    })
  }
}

// 饮食记录相关API
export const dietApi = {
  // 创建饮食记录
  createRecord(data) {
    return request({
      url: '/api/diet/record',
      method: 'post',
      data
    })
  },
  
  // 更新饮食记录
  updateRecord(recordId, data) {
    return request({
      url: `/api/diet/record/${recordId}`,
      method: 'put',
      data
    })
  },
  
  // 获取某日期的饮食记录
  getRecords(date) {
    return request({
      url: '/api/diet/records',
      method: 'get',
      params: { date }
    })
  },
  
  // 获取日期范围内的饮食记录
  getRecordsByDateRange(startDate, endDate) {
    return request({
      url: '/api/diet/records/range',
      method: 'get',
      params: { startDate, endDate }
    })
  },
  
  // 获取最近的饮食记录
  getRecentRecords(limit = 10) {
    return request({
      url: '/api/diet/records/recent',
      method: 'get',
      params: { limit }
    })
  },
  
  // 删除饮食记录
  deleteRecord(recordId) {
    return request({
      url: `/api/diet/record/${recordId}`,
      method: 'delete'
    })
  }
}

// 健康建议相关API
export const healthApi = {
  // 获取健康建议
  getAdvice() {
    return request({
      url: '/api/health/advice',
      method: 'get'
    })
  },
  
  // 获取健康报告
  getReport() {
    return request({
      url: '/api/health/report',
      method: 'get'
    })
  }
}

// AI建议相关API
export const aiApi = {
  // 获取AI健康建议
  getHealthAdvice(data) {
    return request({
      url: '/api/health/advice',
      method: 'get',
      params: data
    })
  }
}